﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VisionCore
{
    public static class ParameterHelper
    {
        public static string FileName_System = "System";
        public static string FileName_ExcST = "ExcST";
        public static string FileName_ExcTR = "ExcTR";
        public static string FileName_RBUpper = "RBUpper";
        public static string FileName_RBLower = "RBLower";
        public static string FileName_SortST = "SortST";
        public static string FileName_SortSTNG = "SortSTNG";
        public static string FileName_Aligner = "Aligner";
        public static string FileName_PortA = "PortA";
        public static string FileName_PortB = "PortB";
        public static string FileName_NGPort1 = "NGPort1";
        public static string FileName_NGPort2 = "NGPort2";
        public static string FileName_Default = "default";

        public static string FileName_LDTR1 = "LDTR_1";
        public static string FileName_LDTR2 = "LDTR_2";
        public static string FileName_LaserST1 = "LaserST1";
        public static string FileName_LaserST2 = "LaserST2";
        public static string FileName_LaserST3 = "LaserST3";
        public static string FileName_LaserST4 = "LaserST4";
        public static string FileName_LaserST5 = "LaserST5";
        public static string FileName_LaserST6 = "LaserST6";
        public static string FileName_LaserST7 = "LaserST7";
        public static string FileName_LaserST8 = "LaserST8";
        public static string FileName_ULDTR1 = "ULDTR_1";
        public static string FileName_ULDTR2 = "ULDTR_2";

        public static string FileName_ULDST = "ULDST";
        public static string FileName_ULDSTNG = "ULDSTNG";
        public static string FileName_ULDTray1 = "ULDTray_1";
        public static string FileName_ULDTray2 = "ULDTray_2";
        public static string FileName_ULDTray3 = "ULDTray_3";
        public static string FileName_ULDTray4 = "ULDTray_4";
        public static string FileName_ULDTray5 = "ULDTray_5";


        public static DAL<SystemModel> mSysDAL = new DAL<SystemModel>(ParamType.System, FileName_System);
        public static DAL<RecipeModel> mRecDAL = new DAL<RecipeModel>(ParamType.Recipe);
        public static DAL<ChipInfo> ExcSTDAL = new DAL<ChipInfo>(ParamType.Glass,FileName_ExcST);
        public static DAL<ChipInfo> ExcTRDAL = new DAL<ChipInfo>(ParamType.Glass, FileName_ExcTR);
        public static DAL<ChipInfo> RBUpperDAL = new DAL<ChipInfo>(ParamType.Glass,FileName_RBUpper);
        public static DAL<ChipInfo> RBLowerDAL = new DAL<ChipInfo>(ParamType.Glass, FileName_RBLower);
        public static DAL<ChipInfo> SortSTDAL = new DAL<ChipInfo>(ParamType.Glass, FileName_SortST);
        public static DAL<ChipInfo> SortSTNGDAL = new DAL<ChipInfo>(ParamType.Glass, FileName_SortSTNG);
        public static DAL<ChipInfo> AlignerDAL = new DAL<ChipInfo>(ParamType.Glass, FileName_Aligner);
        public static DAL<ChipInfo> NGPort1DAL = new DAL<ChipInfo>(ParamType.Glass, FileName_NGPort1);
        public static DAL<ChipInfo> NGPort2DAL = new DAL<ChipInfo>(ParamType.Glass, FileName_NGPort2);
        public static DAL<PortInfo> PortADAL = new DAL<PortInfo>(ParamType.Glass, FileName_PortA);
        public static DAL<PortInfo> PortBDAL = new DAL<PortInfo>(ParamType.Glass, FileName_PortB);

        public static DAL<TrayInfo> ULDSTDAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDST);
        //public static DAL<TrayInfo> ULDSTNGDAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDSTNG);
        public static DAL<NGTrayInfo> ULDSTNGDAL = new DAL<NGTrayInfo>(ParamType.Glass, FileName_ULDSTNG);
        public static DAL<TrayInfo> ULDTray1DAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDTray1);
        public static DAL<TrayInfo> ULDTray2DAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDTray2);
        public static DAL<TrayInfo> ULDTray3DAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDTray3);
        public static DAL<TrayInfo> ULDTray4DAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDTray4);
        public static DAL<TrayInfo> ULDTray5DAL = new DAL<TrayInfo>(ParamType.Glass, FileName_ULDTray5);

        public static DAL<DieInfo> LDTR1DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LDTR1);
        public static DAL<DieInfo> LDTR2DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LDTR2);
        public static DAL<DieInfo> LaserST1DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST1);
        public static DAL<DieInfo> LaserST2DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST2);
        public static DAL<DieInfo> LaserST3DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST3);
        public static DAL<DieInfo> LaserST4DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST4);
        public static DAL<DieInfo> LaserST5DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST5);
        public static DAL<DieInfo> LaserST6DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST6);
        public static DAL<DieInfo> LaserST7DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST7);
        public static DAL<DieInfo> LaserST8DAL = new DAL<DieInfo>(ParamType.Glass, FileName_LaserST8);
        public static DAL<DieInfo> ULDTR1DAL = new DAL<DieInfo>(ParamType.Glass, FileName_ULDTR1);
        public static DAL<DieInfo> ULDTR2DAL = new DAL<DieInfo>(ParamType.Glass, FileName_ULDTR2);

        public static RecipeModel CurParam = new RecipeModel();
        public static SystemModel SysParam = new SystemModel();
        public static ChipInfo CV1 = new ChipInfo();
        public static ChipInfo CV2 = new ChipInfo();
        public static ChipInfo Insp1 = new ChipInfo();
        public static ChipInfo Insp2 = new ChipInfo();
        public static ChipInfo Insp3 = new ChipInfo();
        public static ChipInfo Insp4 = new ChipInfo();

        public static ChipInfo ExcST = new ChipInfo();
        public static ChipInfo ExcTR = new ChipInfo();
        public static ChipInfo RBUpper = new ChipInfo();
        public static ChipInfo RBLower = new ChipInfo();
        public static ChipInfo SortST = new ChipInfo();
        public static ChipInfo SortSTNG = new ChipInfo();
        public static ChipInfo Aligner = new ChipInfo();
        public static ChipInfo NGPort1 = new ChipInfo();
        public static ChipInfo NGPort2 = new ChipInfo();

        public static TrayInfo ULDST = new TrayInfo();
        public static NGTrayInfo ULDSTNG = new NGTrayInfo();
        public static TrayInfo ULDTray1 = new TrayInfo();
        public static TrayInfo ULDTray2 = new TrayInfo();
        public static TrayInfo ULDTray3 = new TrayInfo();
        public static TrayInfo ULDTray4 = new TrayInfo();
        public static TrayInfo ULDTray5 = new TrayInfo();

        public static PortInfo PortA = new PortInfo();
        public static PortInfo PortB = new PortInfo();        

        public static DieInfo LDTR1 = new DieInfo();
        public static DieInfo LDTR2 = new DieInfo();
        public static DieInfo LaserST1 = new DieInfo();
        public static DieInfo LaserST2 = new DieInfo();
        public static DieInfo LaserST3 = new DieInfo();
        public static DieInfo LaserST4 = new DieInfo();
        public static DieInfo LaserST5 = new DieInfo();
        public static DieInfo LaserST6 = new DieInfo();
        public static DieInfo LaserST7 = new DieInfo();
        public static DieInfo LaserST8 = new DieInfo();
        public static DieInfo ULDTR1 = new DieInfo();
        public static DieInfo ULDTR2 = new DieInfo();

        public static HoldHelper MonitorDatas = new HoldHelper();
        

        public static void InitalSetting()
        {
            SysParam = mSysDAL.Load();
            CurParam = mRecDAL.Load(SysParam.CurPRM);
            MonitorDatas.LoadPara();
        }

        public static bool AixsInitalSetting()
        {
            Kernel.motion.CV1_TrackSW_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CV1_TrackSW_Y;
            Kernel.motion.CV1_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CV1_Y;
            Kernel.motion.CV2_TrackSW_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CV2_TrackSW_Y;
            Kernel.motion.CV2_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CV2_Y;

            Kernel.motion.CCD1_X.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD1_X;
            Kernel.motion.CCD1_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD1_Y;
            Kernel.motion.CCD1_Z.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD1_Z;

            Kernel.motion.CCD2_X.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD2_X;
            Kernel.motion.CCD2_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD2_Y;
            Kernel.motion.CCD2_Z.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.CCD2_Z;

            Kernel.motion.Insp1_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.Insp1_Y;
            Kernel.motion.Insp2_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.Insp2_Y;
            Kernel.motion.Insp3_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.Insp3_Y;
            Kernel.motion.Insp4_Y.HomeCrossDistance = ParameterHelper.SysParam.EQ.HomeCrossDistance.Insp4_Y; 
            return true;
        }
        public static string[] GetRecipeNames()
        {
            string strDir = mRecDAL.FileDir;
            string[] dirs = Directory.GetDirectories(strDir);

            for (int i = 0; i < dirs.Length; i++)
            {
                dirs[i] = dirs[i].Replace(strDir,"");
            }

            return dirs;
        }
    }

    public enum ParamType
    {
        Recipe = 1,
        System = 2,
        Glass,
        
        PortPos,
        Wafer,
        Other,

        PAPos,
        PBPos,
    }
}
